import * as power_property from "../system/power_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
export function CallWhaleSupportTrigger() {
    return {
        onUse(source) {
            const player = source.source;
            const item = source.itemStack;
            const container = player.getComponent('inventory')?.container;
            if (!container || !player || !item)
                return;
            if (!achieve_plan.ControlEventTrigger.EntityToken(item.typeId, player, 20))
                return;
            if (!player.dimension.getBlock(player.location)?.isLiquid) {
                player.sendMessage([native_tools.EntityTranslate(player), { text: '-> 请在水下使用, 无法在空气中召唤<§l§9 渊鲸-维系者 §r>' }]);
                return;
            }
            ;
            native_tools.SummoningEntityWithData(player, container, 'entity_machine:whale_support');
        }
    };
}
;
export function CallPythonSentinelTrigger() {
    return {
        onUse(source) {
            const player = source.source;
            const item = source.itemStack;
            const container = player.getComponent('inventory')?.container;
            if (!container || !player || !item)
                return;
            if (!achieve_plan.ControlEventTrigger.EntityToken(item.typeId, player, 20))
                return;
            if (!player.dimension.getBlock(player.location)?.isLiquid) {
                player.sendMessage([native_tools.EntityTranslate(player), { text: '-> 请在水下使用, 无法在空气中召唤<§l§9 渊鲸-维系者 §r>' }]);
                return;
            }
            ;
            native_tools.SummoningEntityWithData(player, container, 'entity_machine:python_sentinel');
        }
    };
}
;
export function CallTunnelDragonGuideTrigger() {
    return {
        onUse(source) {
            const player = source.source;
            const item = source.itemStack;
            const container = player.getComponent('inventory')?.container;
            if (!container || !player || !item)
                return;
            if (!achieve_plan.ControlEventTrigger.EntityToken(item.typeId, player, 20))
                return;
            if (!player.dimension.getBlock(player.location)?.isLiquid) {
                player.sendMessage([native_tools.EntityTranslate(player), { text: '-> 请在水下使用, 无法在空气中召唤<§l§9 渊鲸-维系者 §r>' }]);
                return;
            }
            ;
            native_tools.SummoningEntityWithData(player, container, 'entity_machine:tunnel_dragon_guide');
        }
    };
}
;
export function CallPythonPioneerTrigger() {
    return {
        onUse(source) {
            const player = source.source;
            const item = source.itemStack;
            const container = player.getComponent('inventory')?.container;
            if (!container || !player || !item)
                return;
            if (!achieve_plan.ControlEventTrigger.EntityToken(item.typeId, player, 20))
                return;
            const getEntities = player.getEntitiesFromViewDirection({ maxDistance: 64 })[0];
            const getBlock = player.getBlockFromViewDirection({ maxDistance: 64 });
            const blockDistance = getBlock?.block ? math_tools.Vector.distance(player.location, getBlock?.block) : 48;
            const distance = getEntities?.distance ?? blockDistance;
            const powerExplode = (args) => {
                const options = {
                    excludeTypes: ["minecraft:item", "minecraft:xp_orb"],
                    excludeFamilies: ['starry'],
                    location: args.location,
                    maxDistance: 8,
                    closest: 8
                };
                const entitys = args.dimension.getEntities(options).filter(entity => entity.id !== player.id);
                entitys.forEach(entity => {
                    const erupt = derived_tools.IsErupt(player);
                    const direction = math_tools.Vector.difference(player.location, entity.location);
                    const distance = math_tools.Vector.distance(player.location, entity.location);
                    const mapping = (1 + distance / distance) * 3;
                    power_property.AlterProperty(player, { raise_basic_attack: distance });
                    entity.applyKnockback(direction.x, direction.z, mapping, direction.y * 2);
                    achieve_plan.RunePowerAttack.BriefCreate(player, entity, erupt);
                });
                args.dimension.playSound('random.explode', args.location);
                native_tools.TrySpawnParticle(player.dimension, 'constant:impact_rune_white', args.location);
            };
            achieve_plan.PathExecute.Create('森蚺先锋炮-炮击轨迹', 1, {
                particles: ['constant:smoke_rune_white'],
                dimension: player.dimension,
                on_done: powerExplode,
                location_group: [],
                cooldown: 1,
                speed: 1,
                shoot: {
                    start_place: player.getHeadLocation(),
                    toward: player.getViewDirection(),
                    max_distance: distance,
                }
            });
            player.playSound('mob.irongolem.repair');
            item.getComponent('minecraft:cooldown')?.startCooldown(player);
            native_tools.SetDurability(player, item, container, player.selectedSlotIndex, 1);
        }
    };
}
;
